import request from '@/utils/request'

// 登录 API
export const login = (data) => {
    return request({
        url: '/user/login', // 直接使用后端路径，不要加 /api
        method: 'POST',
        data
    })
}

// 注册 API
export const register = (data) => {
    return request({
        url: '/user/register',
        method: 'POST',
        data
    })
}

// 获取当前用户信息
export const getUserInfo = () => {
    return request({
        url: '/user/me',
        method: 'GET'
    })
}

// 更新个人资料
export const updateProfile = (data) => {
    return request({
        url: '/user/profile',
        method: 'PUT',
        data
    })
}

// 修改密码
export function changePassword(data) {
    console.log("Sending change password request:", data)
    return request({
        url: '/user/change-password',
        method: 'post',
        data
    }).catch(error => {
        console.error("Change password error:", error)
        throw error
    })
}

// 退出登录
export const logout = () => {
    return request({
        url: '/user/logout',
        method: 'POST'
    })
}